﻿using BookManege.entity;
using BookManege.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManege.controller
{
    public partial class stillDetails : Form
    {
        private long applicationId;
        private StillApplication stillApplication;
        private stillbookManage stillbookManage;

        public stillDetails(long applicationId, stillbookManage stillbookManage)
        {
            this.applicationId = applicationId;
            stillApplication = new StillApplication();
            InitializeComponent();
            this.stillbookManage = stillbookManage;
        }

        private void stillDetails_Load(object sender, EventArgs e)
        {
            GetStillDetails();
        }
        public void GetStillDetails()
        {
            StillDetails stillDetails = stillApplication.GetDetails(applicationId);
            if (stillDetails != null)
            {
                label6.Text = stillDetails.BookId.ToString();
                label6.Tag = stillDetails.BorrowId.ToString();
                label7.Text = stillDetails.BookName.ToString();
                label11.Text = stillDetails.Number.ToString();
                label8.Text = stillDetails.UserName.ToString();
                label9.Text = stillDetails.SubmiteDate.ToString();
                if (stillDetails.State.ToString() == "0")
                {
                    label10.Text = "未处理";
                }
                else
                {
                    label10.Text = "已处理";
                    button1.Enabled = button2.Enabled = false;
                }

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (stillApplication.Pass(applicationId, Convert.ToInt64(label6.Text), Convert.ToInt64(label6.Tag), Convert.ToInt32(label11.Text)) > 0)
            {
                MessageBox.Show("通过成功");
                this.Close();
                return;
            }
            MessageBox.Show("系统错误！");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (stillApplication.Refuse(applicationId) > 0)
            {
                MessageBox.Show("驳回成功");
                this.Close();
                return;
            }
            MessageBox.Show("系统错误！");
        }
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            base.OnFormClosed(e);
            stillbookManage.GetStillApplication();
        }
    }
}
